<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .sty1{
            margin-left: 15px;
        }
    </style>
</head>
<body>
    <table border="1" align="center" width="280">
        <tr>
            <td>邮箱：</td>
            <td><input type="text" style="width:95%;" id="email" /></td>
        </tr>
        <tr>
            <td>验证码：</td>
            <td>
                <input type="text" size="1" />
                <input type="button" value="点击获取验证码" class="sty1" onclick="fun()" />
            </td>
        </tr>
    </table>
    <script src="./node_modules/axios/dist/axios.js"></script>
    <script>
        function fun(){
            //获取邮箱
            var email = document.getElementById("email").value;
            var num = 20;
            document.getElementsByClassName("sty1")[0].value="再次获取验证码("+num+")";
            document.getElementsByClassName("sty1")[0].disabled=true;
            var timer = setInterval(function(){
                num--;
                document.getElementsByClassName("sty1")[0].value="再次获取验证码("+num+")";
                if(num == 0){
                    clearInterval(timer);
                    document.getElementsByClassName("sty1")[0].value="点击获取验证码";
                    document.getElementsByClassName("sty1")[0].disabled=false;
                }
            },1000)

            axios.get("http://localhost:3000/emailCode/getValidataCode",
                {params:{"email":email}}
            ).then(function(res){
               //sessionStorage.setItem("phoneCode",res.data.code);
               console.log(res.data)
            }).catch(function(err){
                console.log(err)
            });
        }
    </script>
</body>
</html>